package com.wpml.search.controller;

import com.wpml.common.util.ResultJson;
import com.wpml.search.service.ISaveProductService;
import com.wpml.search.vo.SkuEsModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @description:
 * @author: wp
 * @date: 2019-09-02 10:43
 **/
@RestController
@RequestMapping("/search")
@Slf4j
public class ElasticSaveController {

    @Resource
    ISaveProductService saveProductService;

    @PostMapping("/saveProduct")
    public ResultJson saveProduct(@RequestBody List<SkuEsModel> skuEsList) {

        try {
            boolean save = saveProductService.save(skuEsList);
            log.info("==========上架成功========== {}", !save);
            return ResultJson.ok(!save);
        } catch (IOException e) {
            e.printStackTrace();
            return ResultJson.fail("上架异常");
        }
    }
}
